
//
//  FFDataMode.m
//  fitness-iOS
//
//  Created by 卢仕彤 on 2018/1/6.
//  Copyright © 2018年 卢仕彤. All rights reserved.
//

#import "FFDataMode.h"
#import "FFNetworkHelper.h"

@implementation FFDataMode


+(instancetype)shareCenter{
    static FFDataMode *sharedManager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[FFDataMode alloc] init];
    });
    
    return sharedManager;
}


- (void)get_myInfoModelAPI:(void (^)(BOOL))block {
    
    
    NSString *requestUrl = @"user/getUser";
    NSDictionary *parmsDic = @{};
    if(!_myInfoModel) {
        [FFNetworkHelper POST:requestUrl parameters:parmsDic success:^(id responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                self.myInfoModel = [MeinfoMode yy_modelWithJSON:responseObject[@"data"][@"user"]];
                if (block) {
                    block(YES);
                }
            }
            else{
                if (block) {
                    block(NO);
                }
            }
            
        } failure:^(NSError *error) {
            if (block)
            {
                block(NO);
            }
        }];
    }
    
}

- (MeinfoMode *)userinfo {
    if (!_userinfo || !_userinfo.isNetData) {
        NSString *requestUrl = @"user/getUser";
        NSDictionary *parmsDic = @{};
        
            [FFNetworkHelper POST:requestUrl parameters:parmsDic success:^(id responseObject) {
                if ([responseObject[@"code"] integerValue] == 200) {
                    _userinfo = [MeinfoMode yy_modelWithJSON:responseObject[@"data"][@"user"]];
                    _userinfo.isNetData = YES;
                }
            } failure:^(NSError *error) {
                
            }];
    }
    return _userinfo;
}
- (void)clearData {
    _myInfoModel = nil;
}

- (NSMutableDictionary *)updataInfo:(NSDictionary *)user_dic {
    NSMutableDictionary *updataInfo = [[NSMutableDictionary alloc] init];
    return updataInfo;
}

@end
